<?php

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\cache\Coupon;

$couponId = trim($argv[1]);
$batchCouponCodes = file("coupon-" . $couponId);
$count = 0;
if ($batchCouponCodes) {
    echo "开始为批量优惠卷ID:{$couponId}添加优惠码" . PHP_EOL;
    foreach ($batchCouponCodes as $batchCouponCode) {
        $batchCouponCode = trim($batchCouponCode);
        if ($batchCouponCode) {
            echo "添加优惠码：{$batchCouponCode}" . PHP_EOL;
            Coupon::addBatchCoupon($couponId, $batchCouponCode);
            $count++;
        }
    }
    echo "总共添加{$count}个优惠码" . PHP_EOL;
} else {
    echo "优惠码文件coupon-{$couponId}不存在" . PHP_EOL;
}